# Table D3: Covid-19 Unemployment Effects on Asian Hate Crimes: Shorter Time Frame

rm(list = ls())

setwd('/path/to/replication/')

library(data.table)
library(estimatr)
library(texreg)

load('./data/panel_month_dummies.RData')

out_econ_simple <- lm_robust(hc_pc_asians ~ covid2*losing_income_d, data=panel[month>='2019-01-01'], se_type='stata',
                             clusters = panelvar)


if (!file.exists('./output/out_econ_one_year.RData') &
    !file.exists('./output/out_econ_con_one_year.RData') &
    !file.exists('./output/out_econ_con_trend_one_year.RData') &
    !file.exists('./output/out_econ_con_trend_all_one_year.RData')) {
  source('./code/tableD3reg.R')
}

out_econ <- get(load('./output/out_econ_one_year.RData'))
out_econ_con <- get(load('./output/out_econ_con_one_year.RData'))
out_econ_con_trend <- get(load('./output/out_econ_con_trend_one_year.RData'))
out_econ_con_trend_all <- get(load('./output/out_econ_con_trend_all_one_year.RData'))

tabled3 <- texreg(list(out_econ_simple, out_econ, out_econ_con, out_econ_con_trend, out_econ_con_trend_all),
       include.ci = FALSE,
       include.adjrs = FALSE, include.rmse = FALSE,
       stars = c(0.001, 0.01, 0.05, 0.1), digits = 5,
       custom.coef.map = list('losing_income_d' = 'Expected unemployment', 'covid2'= 'After Jan, 2020', 
                              'covid2:losing_income_d' = 'After Jan, 2020 x Expected unemployment',
                              'covid_econ' = 'After Jan, 2020 x Expected unemployment'),
       symbol = "\\circ",
       caption = "Covid-19 Unemployment Effects on Asian Hate Crimes: Shorter Time Frame",
       caption.above = TRUE)

write(tabled3, file.path('./tableD3.tex'))
